// pages/follow/follow.js
import { My } from '../my/my-model.js';
import { Follow } from '../follow/follow-model.js';
var my = new My();

var follow = new Follow();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loadingHidden: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;

    that._loadData();
  },
  _loadData: function () {
    var that = this;


    //  this.data.tabs[0].num = 
    my.getUserInfo((data) => {
      console.log(data);
      that.setData({
        userInfo: data,
        loadingHidden: true
      });

    });
    wx.getSetting({
      success: (ress) => {

        // console.log(ress.authSetting['scope.userInfo']);
        if (!ress.authSetting['scope.userInfo']) {
          wx.openSetting({
            success: (res) => {
              if (res.authSetting['scope.userInfo'] == true) {
                this._loadData();
                wx.switchTab({
                  url: '../my/my'
                });
              }
            }

          })
        } else {

          wx.getUserInfo({
            success: function (res) {
              // console.log(res);
              var userInfo = res.userInfo
              var nickName = userInfo.nickName
              var avatarUrl = userInfo.avatarUrl
              var gender = userInfo.gender //性别 0：未知、1：男、2：女
              var province = userInfo.province
              var city = userInfo.city
              var country = userInfo.country
            }
          })


          follow.catFollowData((data) => {
            console.log(data)
            that.setData({
              
              followArr: data,
              loadingHidden: true


            });
          });

        }
      }
    })
 
  },
  //去逛逛
  detail: function (event) {

    wx.switchTab({
      url: '../category/category'
    });
  },
  /*跳转到商品详情*/
  onProductsItemTap: function (event) {
    var id = follow.getDataSet(event, 'id');
    wx.navigateTo({
      url: '../product/product?id=' + id
    })
  },

  //分享二维码

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})